package org.kermeta.spem.activityautomation.eclipse.createemptyemfproject;

import org.eclipse.core.resources.IContainer;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;

import org.kermeta.spem.activityautomation.eclipse.createemptyemfproject.EcoreModelWizard2;
import org.kermeta.spem.activityautomation.eclipse.createemptyemfproject.EmptyProjectWizard2;

public class CreateEmptyEMFProject implements IObjectActionDelegate {

	private IStructuredSelection selection;
	private IWorkbenchPart targetPart;
	private IContainer modelContainer;

	public void setActivePart(IAction action, IWorkbenchPart targetPart)
	{
		this.targetPart = targetPart;
	}

	public void selectionChanged(IAction action, ISelection selection) {
		this.selection =
				selection instanceof IStructuredSelection
				? (IStructuredSelection) selection
						: null;
	}

	public void run(IAction action) {

	}

	public void run(IWorkbenchWindow window, String contextModelPath){
		try{
			EmptyProjectWizard2 emptyProjectWizard = new EmptyProjectWizard2(this, contextModelPath);
			emptyProjectWizard.init(window.getWorkbench(), selection);
			WizardDialog dialog = new WizardDialog(window.getShell(), emptyProjectWizard);
			dialog.open();
		}catch(Exception e){
			e.printStackTrace();
			int i = 0;
		}

		StructuredSelection structuredSelection = new StructuredSelection(modelContainer);
		EcoreModelWizard2 ecoreModelWizard = new EcoreModelWizard2(contextModelPath);
		ecoreModelWizard.init(window.getWorkbench(), structuredSelection);
		WizardDialog dialogEcoreModelWizard = new WizardDialog(window.getShell(), ecoreModelWizard);
		dialogEcoreModelWizard.open();
	}

	public void setModelContainer(IContainer modelContainer){
		this.modelContainer = modelContainer;
	}
}
